<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 函数参数里面加3个点 (...ages)  意思就是ages接收所有的参数 并且是以数组的方式接收
        const sum = (...ages) => {
            let total = 0;
            ages.forEach((item) => {   // forEach 遍历数组 item 当前数组的值
                total = total + item;
            });
            return total;
        };
        console.log(sum(10, 20));
        console.log(sum(10, 20, 30));

        let arr = ['张三', '李四', '王五'];
        let [s1, ...s2] = arr; // 此时s1 接收张三的值 ...s2接收剩余的全部值 并且以数组形式接收
        console.log(s1);
        console.log(s2);
    </script>
</body>

</html>